package com.eling.elcms.basedoc.webapp.controller;

import com.eling.elcms.basedoc.model.ComOrgRelation;
import com.eling.elcms.basedoc.service.IComOrgRelationManager;
import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ComOrgRelationCotroller extends BaseFormController{

	@Autowired
	private IComOrgRelationManager comOrgRelationManager;
	
	@RequestMapping("/api/comorgrelation/search*")
	@ResponseBody
	public List<ComOrgRelation> search(@ModelAttribute SearchCondition sc,@ModelAttribute ComOrgRelation cond) {
		if(cond.getOrganization().getPkOrganization() != 1L){
			sc.setQueryCondition(cond);
		}
		return comOrgRelationManager.search(sc); 
	}
	
	@RequestMapping("/api/comorgrelation/query")
    @ResponseBody
    public List<ComOrgRelation> query(@ModelAttribute ComOrgRelation cond){
		if(cond.getOrganization().getPkOrganization() == 1L){
			cond.setOrganization(null);
		}
    	return comOrgRelationManager.query(cond); 
    }
	
	@RequestMapping("/api/comorgrelation/querycom")
    @ResponseBody
    public List<ComOrgRelation> queryCom(@ModelAttribute ComOrgRelation cond){
    	return comOrgRelationManager.queryCom(cond); 
    }
}
